import {getStudent, getSubjects, getVersion, getBook, getIntensiv, getIntensivQuestion} from '@/api/studyApi'
const study = {
    namespaced: true,
    state: {
        selectObj: localStorage.selectObj ? JSON.parse(localStorage.selectObj) : '',
        keyPointsData: localStorage.keyPointsData ? JSON.parse(localStorage.keyPointsData) : {subjectName: '', knowledgeOrChapterName: ''},
        subjectId: localStorage.subjectId ? localStorage.subjectId : '',
        allSubjectArr: localStorage.allSubjectArr ? JSON.parse(localStorage.allSubjectArr) : [],
        isFirst: false
    },
    getters: {
    },
    mutations: {
        setSelectObj (state, obj) {
            state.selectObj = obj
            localStorage.selectObj = JSON.stringify(obj)
        }, 
        setKeyPointsData (state, obj) {
            state.keyPointsData = obj
            localStorage.keyPointsData = JSON.stringify(obj)
        },
        setSubjectId (state, id) {
            state.subjectId = id
            localStorage.subjectId = id
        },
        setAllSubjectArr (state, arr) {
            state.allSubjectArr = arr
            localStorage.allSubjectArr = JSON.stringify(arr)
        }
    },
    actions: {
        // 获取学生信息
        GetStudent ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getStudent(params).then(res => {
                    resolve(res)
                })
            })
        },
        // 获取科目
        GetSubjects ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getSubjects(params).then(res => {
                    resolve(res)
                })
            })
        },
        // 获取版本
        GetVersion ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getVersion(params).then(res => {
                    resolve(res)
                })
            })
        },
        // 获取课本
        GetBook ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getBook(params).then(res => {
                    resolve(res)
                })
            })
        },
        // 获取练习
        GetIntensiv ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getIntensiv(params).then(res => {
                    resolve(res)
                })
            })
        },
        // 获取 强化 题目
        GetIntensivQuestion ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getIntensivQuestion(params).then(res => {
                    resolve(res)
                })
            })
        }
    }
}
export default study
